﻿package lobby.exchangeddata
{
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import lobby.constants.ConstData;
	import lobby.events.LobbyEvent;
	import lobby.common.Utility;
	
	public class TransactionReportInfo extends EventDispatcher
	{
		public var serverDateFrom:String;
		public var serverDateTo:String
		
		public var totalAmount:String;
		
		public var pageNum:uint;
		public var addPage:Boolean = true;
		public var dataTransation:Array;
		public var dataDetailTransation:Array;
		public var transId:String;
		
		public function TransactionReportInfo()
		{
		
		}
		
		public function resultServerDateTime(result:String):void
		{
			var dateArr:Array = result.split("-");
			var splitDate:String = "/";
			var dateTemp:Date;
			var dayTemp:int;
			if (int(dateArr[3]) < 12)
			{
				dayTemp = int(dateArr[2]);
				dateTemp = new Date(int(dateArr[0]), int(dateArr[1]) - 1, int(dateArr[2]) - 1);
				serverDateFrom = dateTemp.getDate() + splitDate + Utility.getMonthString(dateTemp.getMonth() + 1) + splitDate + dateTemp.getFullYear();
				serverDateTo = dayTemp.toString() + splitDate + Utility.getMonthString(int(dateArr[1])) + splitDate + dateArr[0];				
			}
			else
			{
				dayTemp = int(dateArr[2]);
				dateTemp = new Date(int(dateArr[0]), int(dateArr[1]) - 1, int(dateArr[2]) + 1);
				serverDateFrom = dayTemp.toString() + splitDate + Utility.getMonthString(int(dateArr[1])) + splitDate + dateArr[0];
				serverDateTo = dateTemp.getDate() + splitDate + Utility.getMonthString(dateTemp.getMonth() + 1) + splitDate + dateTemp.getFullYear();
			}
			dispatchEvent(new LobbyEvent(LobbyEvent.UPDATE_DATE_REPORT));
		}
		
		public function resultTransactionReport(result:String):void
		{
			dataTransation = new Array();
			var temp:Array = result.split("&");
			this.totalAmount = temp[0].substr(1, temp[0].length - 1);
			
			var totalRecord:Number = Number(temp[1]);
			if (totalRecord % ConstData.NUM_RECORD_TRANSACTION_REPORT == 0)
			{
				this.pageNum = totalRecord / ConstData.NUM_RECORD_TRANSACTION_REPORT;
			}
			else
			{
				this.pageNum = totalRecord / ConstData.NUM_RECORD_TRANSACTION_REPORT + 1;
			}
			trace("result:" + result)
			var index:int = 0;
			for (var i:int = 2; i < temp.length; i++)
			{
				var transactionReportData:Array = new Array();
				transactionReportData = temp[i].split("*");
				trace("transactionReportData:" + transactionReportData)
				var tranInfo:TransactionItemInfo = new TransactionItemInfo();
				tranInfo.setTransactionNo = transactionReportData[index];
				tranInfo.setTransactionId = transactionReportData[index + 1];
				tranInfo.setTransactionType = transactionReportData[index + 2];
				tranInfo.setTransactionResultDate = transactionReportData[index + 3];
				tranInfo.setTransactionTable = transactionReportData[index + 4];
				tranInfo.setTransactionGame = transactionReportData[index + 5];
				tranInfo.setTransactionResult = transactionReportData[index + 6];
				tranInfo.setTransactionBetCode = transactionReportData[index + 7];
				tranInfo.setTransactionAmount = transactionReportData[index + 8];
				tranInfo.setTransactionBalance = transactionReportData[index + 9];
				tranInfo.setTransactionComm = transactionReportData[index + 10];
				if (String(transactionReportData[index + 11]) == "0")
					tranInfo.setMulti = false;
				else
				{
					tranInfo.setMulti = true;
				}
				dataTransation.push(tranInfo);
			}
			
			dispatchEvent(new LobbyEvent(LobbyEvent.UPDATE_TRANSACTION_REPORT, true));
		}
		
		public function resultDetailTransactionReport(result:String):void
		{
			dataDetailTransation = new Array();
			result = result.substr(1, result.length);
			trace("result:" + result);
			var temp:Array = new Array();
			temp = result.split("$");
			var index:int = 0;
			for (var i:int = 0; i < temp.length; i++)
			{
				var transactionReportData:Array = new Array();
				transactionReportData = temp[i].split("@");
				trace("transactionReportData:" + transactionReportData)
				var tranInfo:TransactionDetailItemInfo = new TransactionDetailItemInfo();
				tranInfo.setTransactionBetCode = transactionReportData[index];
				tranInfo.setTransactionAmount = transactionReportData[index + 1];
				tranInfo.setTransactionBalance = transactionReportData[index + 2];
				tranInfo.setTransactionComm = transactionReportData[index + 3];
				dataDetailTransation.push(tranInfo);
			}
			
			dispatchEvent(new LobbyEvent(LobbyEvent.UPDATE_DETAIL_TRANSACTION_REPORT, true));
		}
	}

}